1979F - Kostyanych's Theorem - CodeForces Solution


brute force constructive algorithms graphs interactive

Please click on ads to support us..

Python Code:

import sys

q = lambda d: print("? %d" % d, flush=True) or map(int, (input().split()))

for _ in range(int(input())):
    vx, ops = set(i for i in range(1, int(input()) + 1)), []
    while len(vx) > 2:
        v1, v2 = q(len(vx) - 2)
        vx.remove(v1)
        if v2 > 0:
            ops += [(v1, v2)]
        else:
            v3, _ = q(0)
            vx.remove(v3)
            ops += [(v3, 0), (v1, 0)]
    p1, p2 = list(vx), []
    for v1, v2 in ops[::-1]:
        (p2 if p1[-1] == v2 else p1).append(v1)
    print("! %s" % ' '.join(map(str, p1[::-1] + p2)), flush=True)


Comments

Submit
0 Comments
More Questions

Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number